{% extends "admin/base.html" %}
{% block title %}-修改用户{% endblock %}
{% block user %}current-item{% endblock %}
{% block mainbody %}
    <div class="main">
			<center>
				<h1>编辑用户</h1>
				<span id="error" class="error">{{ error }}</span>
				<form id="user-form" method="post" action="/admin/user_update">
					<table class="table-adduser">
                        <tr>
                            <th><span>id:</span></th>
                            <td>{{ data.pk }}<input type="hidden" class="user_id" name="user_id" value="{{ data.pk }}"></td>
                        </tr>
						<tr>
							<th>
								<span>姓名:</span>
							</th>
							<td>
								<input type="text" class="user_name" name="user_name" maxlength="20" placeholder="max 20" value="{{ data.fields.user_name }}">
							</td>
						</tr>
						<tr>
							<th>
								<span>性别:</span>
							</th>
							<td>
                                <input type="radio" class="user_sex" name="user_sex" value="男" {% ifequal data.fields.user_sex "男" %} checked="checked" {% endifequal %} /><span>男</span>
                                <input type="radio" class="user_sex" name="user_sex" value="女" {% ifequal data.fields.user_sex "女" %} checked="checked" {% endifequal %} /><span>女</span>
							</td>
						</tr>
						<tr>
							<th>
								<span>出生日期:</span>
							</th>
							<td>
								<input type="date" class="user_birth" name="user_birth" value="{{ data.fields.user_birth }}"/>
							</td>
						</tr>
						<tr>
							<th>
								<span>手机号:</span>
							</th>
							<td>
								<input type="text" class="user_phone" name="user_phone" maxlength="11" placeholder="max 11" value="{{ data.fields.user_phone }}">
							</td>
						</tr>
						<tr>
							<th>
								<span>用户名:</span>
							</th>
							<td>
								<input type="text" class="user_nick" name="user_nick" maxlength="20" placeholder="max 20" value="{{ data.fields.user_nick }}">
								<span class="error">*</span>
							</td>
						</tr>
						<tr>
							<th>
								<span>密码:</span>
							</th>
							<td>
								<input type="text" class="user_pwd" name="user_pwd" maxlength="16" placeholder="max 16" value="{{ data.fields.user_pwd }}">
								<span class="error">*</span>
							</td>
						</tr>
						<tr>
							<th>
								<span>管理员:</span>
							</th>
							<td>
                                <input type="radio" class="is_admin" name="is_admin" value="1" {% ifequal data.fields.is_admin True %}checked="checked"{% endifequal %}/><span>是</span>
								<input type="radio" class="is_admin" name="is_admin" value="0" {% ifequal data.fields.is_admin False %}checked="checked"{% endifequal %} /><span>否</span>
							</td>
						</tr>
						<tr>
							<th>
								<span>职位:</span>
							</th>
							<td>
								<input type="radio" class="position" name="position" value="1" {% ifequal data.fields.position True %}checked="checked"{% endifequal %} /><span>领导</span>
								<input type="radio" class="position" name="position" value="0" {% ifequal data.fields.is_admin False %}checked="checked"{% endifequal %} /><span>员工</span>
							</td>
						</tr>
					</table>
					<input type="button" id="submit_btn" value="提交">
				</form>

			</center>
		</div>

		<script src="/public/js/common/jquery-1.12.4.min.js"></script>
		<script>
			$(document).keydown(function(event) {
				if(event.keyCode == 13) {
					submitForm()
				}
			});

			$("#submit_btn").click(function() {
				submitForm()
			})

            function  submitForm() {
                if (checkForm()) {
                    $("#error").html("正在提交...");
                    $("#user-form").submit();
                }
            }

            function checkForm() {
                console.log($("#user_phone").val())
                $("#error").html("");
				if($(".user_nick").val().trim() == '') {
					$("#error").html("请输入nick");
                    return false;
				}
				if($(".user_pwd").val().trim() == '') {
					$("#error").html("请输入pwd");
                    return false;
				}
				return true;
            }

			$(".user_nick").blur(function() {
				checkForm()
			})

            $(".user_pwd").blur(function() {
				checkForm()
			})

		</script>
{% endblock %}

